//skill prices, now allowed to evolve over time
***********ACS Data***********
use "$temp/acs_master", clear //open
drop if school==2

//restrictions and regressoin variables
gen black = (race == 2) //black dummy
gen male = (sex == 1) //sex dummy
gen hispanic = (hispan!=0) //hispanic

//hs sample
keep if year>=2008 & year<=2012
drop if educ<6



gen exp = age - (educ+12)
drop if exp<0
keep statefip year black male hispanic educ wage_hourly perwt bpl age hours exp coll

//wrap up
keep if age>=25 & age<=54
compress
save "$temp/ACS_skill_price_sample", replace

***********Prep Census Data***********
use "$temp/census_master", clear
merge 1:1 serial pernum using "$data/ACS/usa_00047", nogen //family interrelationship stuff
drop if school==2

//sample restrictions
//keep if uhrswork>=36 & uhrswork<=60 //restrict sample based on labor force attachment
//keep if wkswork1>=50 //for ACS comparability

//regression variables
gen black = (race == 2) //black dummy
gen male = (sex == 1) //sex dummy
gen hispanic = (hispan!=0) //hispanic

//hs sample
drop if educ<6
gen exp = age - (educ+12)
drop if exp<0
keep if age>=25 & age<=54
keep statefip year black male hispanic educ wage_hourly perwt bpl age hours exp coll

//wrap up
append using "$temp/ACS_skill_price_sample" //add on ACS sample
compress
save "$temp/skill_price_dynamics_sample", replace


use "$temp/skill_price_dynamics_sample", clear
gen period = 1
replace period = 2 if year>=2008
ren statefip stfips
gen exp2 = exp^2
gen exp3 = exp^3
gen exp4 = exp^4

//log wage variable
gen l_wage = log(wage_hourly)

//regression based on strategy
reg l_wage black male hispanic exp exp2 exp3 exp4 i.bpl#c.exp i.bpl#c.exp2 i.bpl#c.exp3 i.bpl#c.exp4 ib19.stfips#ib1.period#ib0.coll [fweight=perwt], robust

//convert to data
levelsof stfips, clean local (fips)
clear
set obs 50
gen statefips = .
gen skill_price_p1_hs = .
gen skill_price_p2_hs = .
gen skill_price_p1_coll = .
gen skill_price_p2_coll = .
local counter = 0

//loop over fips and fill in skill prices
foreach fip in `fips'{
	local counter `++counter'
	
	replace statefips = `fip' in `counter'
	replace skill_price_p1_hs = _b[`fip'.stfips#1.period#0.coll] in `counter'
	replace skill_price_p2_hs = _b[`fip'.stfips#2.period#0.coll] in `counter'
	replace skill_price_p1_coll = _b[`fip'.stfips#1.period#1.coll] in `counter'
	replace skill_price_p2_coll = _b[`fip'.stfips#2.period#1.coll] in `counter'
}	

//exponentiate and save
replace skill_price_p1_hs = exp(skill_price_p1_hs)
replace skill_price_p2_hs = exp(skill_price_p2_hs)
replace skill_price_p1_coll = exp(skill_price_p1_coll)
replace skill_price_p2_coll = exp(skill_price_p2_coll)
ren skill_price_p1_hs skill_price_2000_hs_v2
ren skill_price_p2_hs skill_price_2010_hs_v2
ren skill_price_p1_coll skill_price_2000_coll_v2
ren skill_price_p2_coll skill_price_2010_coll_v2

save "$temp/skill_prices_prototype", replace


use "$temp/skill_prices_prototype", clear
merge 1:1 statefips using "$temp/skill_prices_all"

//standardized naming
ren skill_price_2000 skill_price_2000_hs_v1
ren skill_price_2010 skill_price_2010_hs_v1
ren skill_price_2000_hs skill_price_2000_hs_v2
ren skill_price_2010_hs skill_price_2010_hs_v2
ren skill_price_2000_coll skill_price_2000_coll_v2
ren skill_price_2010_coll skill_price_2010_coll_v2
ren skill_price_coll_2000 skill_price_2000_coll_v1
ren skill_price_coll_2010 skill_price_2010_coll_v1

corr skill_price_2000_hs*
corr skill_price_2010_hs*
corr skill_price_2000_coll*
corr skill_price_2010_coll*


//scatterplots
scatter skill_price_2000_hs_v2 skill_price_2000_hs_v1 || line skill_price_2000_hs_v1 skill_price_2000_hs_v1, bgcolor(white) graphregion(color(white)) xtitle("Baseline") ytitle("Experience x BPL") legend(off)
graph export "$output/skill_price_exp_bpl_hs_2000.png", replace

scatter skill_price_2010_hs_v2 skill_price_2010_hs_v1 || line skill_price_2010_hs_v1 skill_price_2010_hs_v1, bgcolor(white) graphregion(color(white)) xtitle("Baseline") ytitle("Experience x BPL") legend(off)
graph export "$output/skill_price_exp_bpl_hs_2010.png", replace

scatter skill_price_2000_coll_v2 skill_price_2000_coll_v1 || line skill_price_2000_coll_v1 skill_price_2000_coll_v1, bgcolor(white) graphregion(color(white)) xtitle("Baseline") ytitle("Experience x BPL") legend(off)
graph export "$output/skill_price_exp_bpl_coll_2000.png", replace

scatter skill_price_2010_coll_v2 skill_price_2010_coll_v1 || line skill_price_2010_coll_v1 skill_price_2010_coll_v1, bgcolor(white) graphregion(color(white)) xtitle("Baseline") ytitle("Experience x BPL") legend(off)
graph export "$output/skill_price_exp_bpl_coll_2010.png", replace
graph close




exit




//end of dofile

